#ifndef SQLWLISTTABLEMODEL_H
#define SQLWLISTTABLEMODEL_H

#include <QSqlTableModel>
#include <QSqlRecord>

class SqlWlistTableModel : public QSqlTableModel
{
    Q_OBJECT
public:
    enum ColumnType {
        StudyUid,
        AccNumber,
        PatientId,
        PatientName,
        PatientSex,
        PatientBirth,
        PatientAge,

        ReqPhysician,
        ReqProcPrio,
        ReqProcId,
        ReqProcDesc,

        Modality,
        SchDateTime,
        SchPhysician,
        SchStationAe,
        SchStationName,
        SchProcStepId,
        SchProcStepDesc,

        AdmissionId,
        Department,
        PatientSize,
        PatientWeight,
        PatientPhone,
        PatientAddr,
        MedicalAlerts,
        CreateTime,
        ModifyTime,

        ColumnCount,
    };

    explicit SqlWlistTableModel(QObject *parent = 0);
    QVariant data(const QModelIndex &idx, int role) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    static bool initWlistDb(QString &result, bool recreate = false);

signals:
    void newPatient(QSqlRecord &rec);
    void newStudy(QSqlRecord &rec);
    void changeStudy(QSqlRecord &rec);
    void removeStudy(QSqlRecord &rec);

protected slots:
    void onNewPatient(const QModelIndex &index);
    void onNewStudy(const QModelIndex &index);
    void onChangeStudy(const QModelIndex &index);
    void onRemoveStudy(const QModelIndex &index);

public slots:
    void onNewPatient(QSqlRecord &rec);
    void onNewStudy(QSqlRecord &rec);
    void onChangeStudy(QSqlRecord &rec);
    void onRemoveStudy();

private:
    void init();

    int currentRow;

};

#endif // SQLWLISTTABLEMODEL_H
